﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq;
using QLKetNoi;

namespace QLPhanQuyen.DAO
{
    public class VaiTroChucNangDAO
    {
        QLDNDataContext db = new QLDNDataContext();
        Table<VAITRO_CHUCNANG> vtcns;
        public bool ThemVaiTroChucNang(VAITRO_CHUCNANG VTCN)
        {
            VAITRO_CHUCNANG vtcn = new VAITRO_CHUCNANG();
            vtcn.MaVaiTro = VTCN.MaVaiTro;
            vtcn.MaChucNang = VTCN.MaChucNang;

            try
            {
                vtcns.InsertOnSubmit(vtcn);
                db.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public List<string> LayChucNangTheoVaiTro(string maVaiTro)
        {
            vtcns = db.GetTable<VAITRO_CHUCNANG>();

            var query = (from vc in vtcns
                         where vc.MaVaiTro == maVaiTro
                         select vc.MaChucNang).ToList();
            return query;
        }
    }
}
